<?php

require 'functions.php';
require_once 'data/data.php';
header("Content-type:text/html;charset=utf-8");

$id =  $_POST['id'];
$email = input('email');
$username = input('username','Guest');
$age = input('age',18);
$gender = input('gender',1);
$courses = input('course',[]);
$courses = implode(',', $courses);
$birth = input('birth',1995-01-01);
$attr = input('attr',1);
$description = input('describ');

if (empty($email)) {
	error("邮箱不能为空","user_info.php?op=2&id=$id");
	return;
}

if (!filter_var($email,FILTER_VALIDATE_EMAIL)) {
	error("请输入正确的邮箱格式","user_info.php?op=2&id=$id");
	return;
}

if (empty($username)) {
	error("请输入用户名","user_info.php?op=2&id=$id");
	return;
}

$sql = "update user set email=?,user_name=?,gender=?,courses=?,birthday=?,attr=?,introduction=? where id=?";
$args = [$email,$username,$gender,$courses,$birth,$attr,$description,$id];
if (execute($sql, $args)) {
   success('修改用户信息成功');
} else {
   error('修改用户信息失败',"user_info.php?op=2&id=$id");
}